package com.pingan;


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {

    public static void main(String[] args) throws Exception {
        //\WEB-INF\lib\animal-sniffer-annotations-1.14.jar
        Main main = new Main();
        main.scanWar();
    }

    public void scanJar() throws IOException {
        JarFile file = new JarFile("D:\\test\\animal-sniffer-annotations-1.14.jar");
        Enumeration<JarEntry> entries = file.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            //System.out.println(jarEntry.getName());
            InputStream inputStream = file.getInputStream(jarEntry);

            JarInputStream jarStream=new JarInputStream(inputStream);
            while (jarStream.getNextEntry()!=null){
                ZipEntry nextEntry = jarStream.getNextEntry();
                System.out.println(nextEntry.getName());
            }
        }
    }

    private  void scanWar() throws IOException {
        JarFile file = new JarFile("D:\\test\\seckill.war");

        Enumeration<JarEntry> entries = file.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();


            if (jarEntry.getName().startsWith("WEB-INF/lib")) {
                if (!jarEntry.isDirectory()) {
                    //System.out.println(jarEntry);
                    InputStream jarStream = file.getInputStream(jarEntry);

                    JarInputStream jarInputStream = new JarInputStream(jarStream);

                    /*while (jarInputStream.getNextEntry() != null) {
                        JarEntry libEntry = (JarEntry) jarInputStream.getNextEntry();
                        if (libEntry != null && libEntry.getName().endsWith("class")) {
                            //System.out.println(libEntry);
                        }
                        System.out.println("res: "+libEntry.getName()+" == isD: "+libEntry.isDirectory()+" ="+libEntry.);
                    }
                    break;*/
                }
            }

        }
    }
}
